package com.chima.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.chima.domain.PostCompetent;

public class PostCompetentDao extends HibernateDaoSupport {
	
	//分页查询
			public List<PostCompetent> findByCriteria(DetachedCriteria criteria, int firstResult,int maxResults) {
				return this.getHibernateTemplate().findByCriteria(criteria,firstResult,maxResults);
			}
		   //查找总页数
			public int findByTotalCount() {
				List list= this.getHibernateTemplate().find("select count(*) from PostCompetent");
				long temp = (Long) list.get(0);
				return (int) temp;
			}
			public void save( PostCompetent  postCompetent) {
				this.getHibernateTemplate().save( postCompetent);
			}
			public void update(PostCompetent  postCompetent) {
				this.getHibernateTemplate().update( postCompetent);
			}
			
			public void delete( int id) {
				this.getHibernateTemplate().delete( this.getHibernateTemplate().load(PostCompetent.class, id));
				
			}
			public PostCompetent findByGradeAndWorkyaer(String grade, String workyear) {
				Session session=this.getSession();
				PostCompetent  p=(PostCompetent) session.createQuery("from PostCompetent where grade=? and workyear=? ").setParameter(0, grade).setParameter(1, workyear).uniqueResult();
				super.releaseSession(session);
				return p;
				
			}
			public PostCompetent findPostCompetent(String grade, String workyear,String education, int zhiban) {
				Session session=this.getSession();
				PostCompetent  p=(PostCompetent) session.createQuery("from PostCompetent where grade='"+grade+"' and workyear='"+workyear+"' and education='"+education+"' and zhiban="+zhiban+" ").uniqueResult();
				super.releaseSession(session);
				return p;
			}
}
